<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
<style type="text/css">
.col-xs-12 table {
	border-right: 1px solid #ccc;
	border-bottom: 1px solid #ccc;
	width: 99%;
}

.col-xs-12 table tr {
	height: 40px;
}

.col-xs-12 table tr td {
	border-left: 1px solid #ccc;
	border-top: 1px solid #ccc;
}

.col-xs-12 table tr.ddt:hover {
	background-color: #ecf3f8
}
.ddt td{
	padding-left:10px;
}
</style>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>

</head>
<body>
	<div>
		<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 queryDiv" style="width: 95%">
        	<header style="height: 95%;margin-top: 8px">
                    <div align="left">
	                    <table style="width: 95%;border:0px;">
	                   		<tr>
	                   			<td style="border:0px;">
									<form class="form-inline" onsubmit="return false">
										<div class="form-group"  style="width: 95%">
											<span style="display: block;float:left;line-height: 32px;">关键字：</span>
											<input id="orgName" type="text" class="form-control" placeholder="机构名称" style="width:200px;float:left;">&nbsp;&nbsp;
											<button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>
										</div>
									</form>
								</td>
	                   		</tr> 
	                    </table>
					</div>
                </header>
			<table class="queryTable">
				<tr>
					<td style="width: 30px;"></td>
					<td style="font-weight: bold;text-align: center;">机构名称</td>
					<td style="font-weight: bold;text-align: center;">上级机构</td>
				</tr>
			</table>
		</div>
		<input type="hidden" id="ids" >
		<input type="hidden" id="names" >
	</div>
</body>
<script type="text/javascript">
	var type = GetQueryString("type");//流程
	var checkbox = GetQueryString("checkbox");//多选操作
	var ids = [];
	var names = [];
	$(function() {
		$("#searchBt").click(function(){
			loadD();
		});
	});
	function initData(){
		if($("#ids").val())
			ids = $("#ids").val().split(',');
		if($("#names").val())
			names = $("#names").val().split(',');
	}
	function init(){
		$.ajax({
			type : 'get',
			url :  urlRootPrefix + '/orgs/all?all=false&keys='+$("#orgName").val(),
			contentType : 'application/json',
			success : function(data) {
				if (data.statusCode == "0") {
					var cc = data.data;
					if (cc) {
						$(".queryDiv .queryTable .ddt").remove();
						for (var i = 0; i < cc.length; i++) {
							$(".queryDiv .queryTable").append('<tr class="ddt"><td style="text-align:center"><input  name="ckbquery" type="'+(checkbox==1?"checkbox":"radio")+'" ' + (ids.indexOf(cc[i].orgId) > -1 ? 'checked': '') + ' id="ckbquery'+ cc[i].orgId + '" value="'+ cc[i].orgId + '" valuen = "'+ cc[i].orgName+ '"/></td><td>'+ cc[i].orgName+ '</td><td>'+ (cc[i].parentName ? cc[i].parentName: "无")+ '</td></tr>');
						}
						$(".queryDiv .queryTable .ddt,.queryDiv .queryTable .ddt input").click(function(event) {
		                	var isc;
		                	var vid;
		                	var vname;
		                	if($(this).prop("tagName") == "TR"){
			                	if($(this).find("input").is(':checked')){
			                		isc = false;
			                		$(this).find("input").prop('checked', isc);
			                	}else{
			                		isc = true;
			                		$(this).find("input").prop('checked', isc);
			                	}
			                	vid = $(this).find("input").attr("value");
			                	vname = $(this).find("input").attr("valuen");
		                	}else{
			                	isc = $(this).is(':checked');
			                	vid = $(this).attr("value");
			                	vname = $(this).attr("valuen");
			                	event.stopPropagation();//不触发父元素事件
		                	}
		                	if(checkbox == 1){
			                	var index = ids.indexOf(vid);//该值在数组中的位置
			                	if(index == -1){
			                		ids.push(vid);
			                		names.push(vname);
			                	}else{
			                		ids.splice(index, 1); 
			                		names.splice(index, 1); 
			                	}
			                	$("#ids").val(ids.join(","));
			                	$("#names").val(names.join(","));
		                	}else{
		                		$("#ids").val(vid);
			                	$("#names").val(vname);
		                	}
		                });
					} else {
						alert(data.msg);
					}
				}
			}
		});
	}
</script>
</html>